﻿@{
    var plugName = @brand.admin.cyt369.com.Areas.BrandAdmin.Models.PlugName.Name;
    var tableName = PageViewModel.PageTableID(this, plugName);
    var tableToolBar = PageViewModel.PageTableToolbar(this, plugName);
    var menu_table_load_success = PageViewModel.ControlID(this, "menu_table_load_success", plugName);

    var menu_module_list_id = PageViewModel.ControlID(this, "menu_module_list", plugName);
    var menu_operation_list_id = PageViewModel.ControlID(this, "menu_operation_list", plugName);

    var on_selet_menu = PageViewModel.PageFunctionName(this, "on_selet_menu", plugName);

    var editFunName = PageViewModel.PageFunctionName(this, "edit", plugName);
    var editDlgName = PageViewModel.PageEditDialog(this, plugName);
    var saveEditFunName = PageViewModel.PageFunctionName(this, "save_edit", plugName);

    var deleteFunName = PageViewModel.PageFunctionName(this, "delete", plugName);

}


<script type="text/javascript">
    function @editFunName (id) {
        var dlg = $dlg('@editDlgName');
        dlg.dialog({
            title: '品牌类别编辑', width: 600, height: 300, closed: false, cache: false, modal: true, maximizable: false, resizable: false, maximized: false,
            href: '~/@plugName/Category/_EditCategory',
            onResize: function () { $(this).dialog('center'); },
            buttons: [
                {
                    text: "保 存",
                    handler: function () { @saveEditFunName (); },
                    iconCls: "icon-save"
                }, {
                    text: "取 消",
                    handler: function () { $("#@editDlgName").dialog("close"); },
                    iconCls: "icon-cancel"
                }
            ],
            onLoad: function () {
                LoadObject(id, "~/@plugName/Category/GetCategoryByID/", function (category) {
                    var form = $("#@editDlgName").find("form");
                    form.form("load", category);
                });
            }
        });
    }
    


    function @saveEditFunName () {
        var form = $("#@editDlgName").find("form");
        if (form.form('enableValidation').form('validate')) {
            var category = form.form_to_json(function (form, category) {
            });
            $.ajax({
                url: "~/@plugName/Category/SaveCategory",
                type: "POST",
                data: category,
                success: function (e) {
                    if (e.Result) {
                        $.messager.alert('保存成功', '保存成功!', 'info', function () {
                            $('#@editDlgName').dialog('close');
                        });
                    } else {
                        $.messager.alert('保存失败', '保存失败: ' + e.Msg, 'error');
                    }
                },
                error: function (e) {
                    ShowAjaxError(e);
                }
            });
        }
    }
</script>
 

<script type="text/javascript">
    function @deleteFunName (id){
        if (id > 0 && confirm("确认删除菜单信息?")) {
            $.ajax({
                async: false,
                method: "DELETE",
                url: $.Content("~/Systems/DeleteCategory/" + id),
                context: $("#@tableName"),
                success: function (e) {
                    if (e.Result) {
                        this.treegrid('remove', id);
                    } else {
                        $.messager.alert('删除数据错误', '删除失败: ' + e.Msg, 'error');
                    }
                },
                error: function (e1, e2, e3) {
                    ShowAjaxError(e1, "删除数据错误");
                    this.treegrid('reload');
                }
            });
        }
    }
</script>


<script type="text/javascript">
    function @on_selet_menu (row) {
        if (row != null) {
            $("#@menu_operation_list_id").datalist("reload", '~/Category/GetCategoryByParentID/' + row.Id);
        }
    }
    function @menu_table_load_success (row, data) {
        if (data.length > 0) {
            $("#@tableName").treegrid('collapseAll');
            $("#@tableName").treegrid("select", data[0].Id);
        }
    }
</script>

<table id="@tableName" class="easyui-treegrid" style="width:100%;" rownumbers="true" fit="true" fitcolumns="true"
       data-options="striped:true,border:false,idField: 'Id',url:'~/@plugName/Category/GetCategoryByParentID',treeField: 'CategoryName',collapsible:true,toolbar:'#@tableToolBar',onSelect:@on_selet_menu,onLoadSuccess:@menu_table_load_success">
    <thead>
        <tr>
            <th data-options="field:'_edit',align:'center',formatter:function(v,r,i){
                                    return GridRowEditFmt('@editFunName', r.Id);
                            }" width="50">修改</th>
            <th data-options="field:'_remove',align:'center',formatter:function(v,r,i){
                                    return GridRowDeleteFmt('@deleteFunName', r.Id);
                            }" width="50">删除</th>
            <th data-options="field:'Id'" width="100">类别编号</th>
            <th data-options="field:'CategoryName'" width="180">类别名称</th>
            <th data-options="field:'Note'" width="250">类别说明</th>
            <th data-options="field:'OrderNumber'" width="200">顺序号</th>
        </tr>
    </thead>
</table>
<div id="@tableToolBar" class="table-toolbar">
    <a href="javascript:@editFunName ()" class="easyui-linkbutton t-btn"><i class="fa fa-plus-circle" style="color:green"></i><span>新增</span></a>
</div>